package oop.ex3.serverprotocol;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import oop.ex3.nameserver.NameServer;
import oop.ex3.sharedclasses.IPaddress;

/**
 * Handles a ContainFile Message sent after a WELCOME Message.
 * Receives the ContainFile message's file name.
 * @author zablo
 *
 */
public class WelcomeContainFile extends ClientMessageHandler{
	private String _fileName;
	
	/**
	 * Returns fileName of this ContainFile Message.
	 * @return the fileName of this ContainFile Message.
	 */
	public String getFileName(){
		return this._fileName;
	}
	
	/**
	 * Will handle a WelcomeContainFile Message.
	 * Will save the file name in this instance.
	 */
	public boolean run(NameServer server,  IPaddress sessionIP,
			DataInputStream clientInput, DataOutputStream clientOutput) {
	try {
		this._fileName=clientInput.readUTF();
		if (endsWithEnd(clientInput)==FAILURE){
			return FAILURE;
		}
	} catch (IOException e) {
		e.printStackTrace();
		return FAILURE;
	}
	
	return SUCCESS;	
	}

}
